#pragma once
#include "WidgetInspector.h"

#include <QHBoxLayout>
#include <QVBoxLayout>
#include <QFormLayout>
#include <QStackedLayout>

#include "FlowLayout.h"

#include <QSplitter>
#include <QScrollArea>

#include <QLabel>
#include <QLineEdit>
#include <QTextEdit>
#include <QComboBox>

class WidgetInspectorUi {
    WidgetInspector *mWidget{nullptr};
public:
    WidgetInspectorUi() = default;
    void SetupUI(WidgetInspector *widget);
    void RetranslateUI();
    inline QString TR(const char *sourceText, const char *disambiguation = nullptr, int n = -1) {
        return mWidget->tr(sourceText, disambiguation, n);
    }

public:
    QLabel *labelObjectName{nullptr};
    QLineEdit *editObjectName{nullptr};
    QLabel *labelClassName{nullptr};
    QLineEdit *editClassName{nullptr};
    QLabel *labelInheritHierarchy{nullptr};
    QLineEdit *editInheritHierarchy{nullptr};
    QLabel *labelObjectHierarchy{nullptr};
    QScrollArea *areaObjectHierarchy{nullptr};
    FlowLayout *layoutObjectHierarchyContents{nullptr};
    QLabel *labelPosition{nullptr};
    QLineEdit *editPosition{nullptr};
    QLabel *labelSize{nullptr};
    QLineEdit *editSize{nullptr};
    QLabel *labelStylsheet{nullptr};
    QTextEdit *editStylesheet{nullptr};

    QLabel *labelUnderCursorColor{nullptr};
    QLineEdit *editUnderCursorColor{nullptr};
    QComboBox *comboboxColorFormat{nullptr};

    QLabel *labelDebugMessage{nullptr};
    QTextEdit *editDebugMessage{nullptr};
};

inline void WidgetInspectorUi::SetupUI(WidgetInspector *widget) {
    mWidget = widget;

    const auto layoutPropert = new QFormLayout;
    layoutPropert->setContentsMargins(0,0,0,0);
    // ObjectName
    labelObjectName = new QLabel;
    editObjectName = new QLineEdit;
    layoutPropert->addRow(labelObjectName, editObjectName);
    // ClassName
    labelClassName = new QLabel;
    editClassName = new QLineEdit;
    layoutPropert->addRow(labelClassName, editClassName);
    // InheritHierarchy
    labelInheritHierarchy = new QLabel;
    editInheritHierarchy = new QLineEdit;
    layoutPropert->addRow(labelInheritHierarchy, editInheritHierarchy);
    // ObjectHierarchy
    labelObjectHierarchy = new QLabel;

    layoutObjectHierarchyContents = new FlowLayout;
    layoutObjectHierarchyContents->setContentsMargins(0,0,0,0);
    layoutObjectHierarchyContents->setHorizontalSpacing(3);
    layoutObjectHierarchyContents->setVerticalSpacing(3);

    auto objectHierarchyContentWidget = new QWidget;
    objectHierarchyContentWidget->setLayout(layoutObjectHierarchyContents);
    areaObjectHierarchy = new QScrollArea;
    areaObjectHierarchy->setWidgetResizable(true);
    areaObjectHierarchy->setWidget(objectHierarchyContentWidget);
    layoutPropert->addRow(labelObjectHierarchy, areaObjectHierarchy);
    // Position
    labelPosition = new QLabel;
    editPosition = new QLineEdit;
    layoutPropert->addRow(labelPosition, editPosition);
    // Size
    labelSize = new QLabel;
    editSize = new QLineEdit;
    layoutPropert->addRow(labelSize, editSize);
    // Stylesheet
    labelStylsheet = new QLabel;
    editStylesheet = new QTextEdit;
    layoutPropert->addRow(labelStylsheet, editStylesheet);

    const auto propertyContentsWidget = new QWidget;
    propertyContentsWidget->setLayout(layoutPropert);

    const auto propertyScrollArea = new QScrollArea;
    propertyScrollArea->setWidgetResizable(true);
    propertyScrollArea->setWidget(propertyContentsWidget);

    labelUnderCursorColor = new QLabel;
    editUnderCursorColor = new QLineEdit;
    comboboxColorFormat = new QComboBox;
    auto layoutColor = new QHBoxLayout;
    layoutColor->addWidget(labelUnderCursorColor);
    layoutColor->addWidget(editUnderCursorColor);
    layoutColor->addWidget(comboboxColorFormat);

    labelDebugMessage = new QLabel;
    editDebugMessage = new QTextEdit;
    auto layoutDebug = new QVBoxLayout;
    layoutDebug->addWidget(labelDebugMessage);
    layoutDebug->addWidget(editDebugMessage);

    auto layoutTool = new QVBoxLayout;
    layoutTool->addLayout(layoutColor);
    layoutTool->addLayout(layoutDebug);

    auto panelTool = new QWidget;
    panelTool->setLayout(layoutTool);

    auto splitter =new QSplitter;
    splitter->setOpaqueResize(true);
    splitter->addWidget(propertyScrollArea);
    splitter->addWidget(panelTool);
    splitter->setStretchFactor(0, 1);

    auto layout = new QHBoxLayout;
    layout->addWidget(splitter);

    mWidget->setLayout(layout);
    RetranslateUI();
    mWidget->adjustSize();
}

inline void WidgetInspectorUi::RetranslateUI() {
    labelObjectName->setText(TR("Object Name"));
    labelClassName->setText(TR("Class Name"));
    labelInheritHierarchy->setText(TR("Inherit Hierarchy"));
    labelObjectHierarchy->setText(TR("Object Hierarchy"));
    labelPosition->setText(TR("Position"));
    labelSize->setText(TR("Size"));
    labelStylsheet->setText(TR("Stylesheet"));
    labelUnderCursorColor->setText(TR("Screen Color"));
    labelDebugMessage->setText(TR("Debug Messages"));
}
